﻿using Model;
using NPOI.SS.Formula.Functions;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 纺织贸易管理系统;

namespace 后整理管理系统.选择窗体
{
    public partial class 历史工艺 : Sunny.UI.UIForm
    {
        public string CustomerName { get; set; } = string.Empty;
        public string Pingming { get; set; }= string.Empty;
        public string gongyimingcheng {  get; set; } = string.Empty;
        public List<liuzhuanmingxi> liuzhuangkamingxi { get; set; } = new List<liuzhuanmingxi>();
        public 历史工艺()
        {
            InitializeComponent();
            dataGridView1.AutoGenerateColumns = false;
            gridControl1.DataSource = liuzhuangkamingxi;
        }

        private void 历史工艺_Load(object sender, EventArgs e)
        {
            query();
        }
        private void query()
        {
            if (radioButton1.Checked)
            {
                var liuzhuancard =Connect.dbcontext.Queryable<Liuzhuancard >().Where (x => x.Customer == CustomerName && x.Pingming == Pingming).OrderByDescending(x => x.ID).ToPageList (0,100);
                dataGridView1.DataSource = null;
                dataGridView1.Columns[1].DataPropertyName = "Beizhu";
                dataGridView1.Columns[0].DataPropertyName = "CardNum";
                dataGridView1.DataSource = liuzhuancard;
            }
            else
            {
                dataGridView1.DataSource = null;
                var mingxi = Connect.dbcontext.Queryable<DanjuTable>().LeftJoin<danjumingxitable>((x, y) => x.dh == y.danhao).Where((x, y) => x.ksmc == CustomerName && y.pingming == Pingming&&x.djlx==DanjuLeiXing.打样单 ).OrderByDescending((x, y) => x.id).ToPageList(0, 100);
                dataGridView1.Columns[1].DataPropertyName = "bz";
                dataGridView1.Columns[0].DataPropertyName = "dh";
                dataGridView1.DataSource = mingxi;
            }
            dataGridView1_CellClick(null, null);
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            query();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
          this.Close ();
        }

        private void 历史工艺_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                gongyimingcheng = dataGridView1.CurrentRow.Cells[ColName .Name ].Value .ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close ();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                string cardnum = dataGridView1.CurrentRow.Cells[cdanhao.Name].Value.ToString();
                if (radioButton1.Checked)
                {
                     liuzhuangkamingxi = liuzhuanmingxiService.Getliuzhuanmingxilst(x => x.CardNum == cardnum);
                    gridControl1.DataSource = liuzhuangkamingxi;
                    gridControl1.RefreshDataSource();
                }
                else
                {
                    var req=Connect.dbcontext.Queryable<ProofingRequirements>().First (x=>x.DocNum ==cardnum );                
                    if (req!=null)
                    {
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "水压" ,Beizhu =req.Hydraulic });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "透湿", Beizhu = req.MoisturePermeability  });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "水洗", Beizhu = req.Washing });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "测试标准", Beizhu = req.TestStandards });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "克重", Beizhu = req.Weight });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "门幅", Beizhu = req.Width });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "切边", Beizhu = req.Trimming });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "正方面", Beizhu = req.FrontOrBack });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "防水效果", Beizhu = req.WaterproofEffect });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "辊型", Beizhu = req.Sticktype });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "胶水", Beizhu = req.Glue });
                        liuzhuangkamingxi.Add(new liuzhuanmingxi() { GongyiYaoqiu = "TPU型号", Beizhu = req.TPU });
                        gridControl1.DataSource = liuzhuangkamingxi;
                        gridControl1.RefreshDataSource();
                    }
                }
            }
            else
            {
                gridControl1.DataSource = null;
                liuzhuangkamingxi = new List<liuzhuanmingxi>();
                gridControl1.RefreshDataSource();
            }

        }
    }
}
